package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserWishGift;
import com.qinggeng.project.system.service.IUserWishGiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 订单商品赠品Controller
 *
 * @author qinggeng
 * @date 2020-07-27
 */
@RestController
@RequestMapping("/system/ordersGoodsGift")
public class UserWishGiftController extends BaseController
{
    @Autowired
    private IUserWishGiftService userWishGiftService;

    /**
     * 查询订单商品赠品列表
     */
    @PreAuthorize("@ss.hasPermi('system:gift:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserWishGift ordersGoodsGift)
    {
        startPage();
        List<UserWishGift> list = userWishGiftService.selectUserWishGiftList(ordersGoodsGift);
        return getDataTable(list);
    }

    /**
     * 导出订单商品赠品列表
     */
    @PreAuthorize("@ss.hasPermi('system:gift:export')")
    @Log(title = "订单商品赠品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserWishGift ordersGoodsGift)
    {
        List<UserWishGift> list = userWishGiftService.selectUserWishGiftList(ordersGoodsGift);
        ExcelUtil<UserWishGift> util = new ExcelUtil<>(UserWishGift.class);
        return util.exportExcel(list, "gift");
    }

    /**
     * 获取订单商品赠品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:gift:query')")
    @GetMapping(value = "/{ordersGoodsGiftId}")
    public AjaxResult getInfo(@PathVariable("ordersGoodsGiftId") Long ordersGoodsGiftId)
    {
        return AjaxResult.success(userWishGiftService.selectUserWishGiftById(ordersGoodsGiftId));
    }

    /**
     * 新增订单商品赠品
     */
    @PreAuthorize("@ss.hasPermi('system:gift:add')")
    @Log(title = "订单商品赠品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserWishGift ordersGoodsGift)
    {
        return toAjax(userWishGiftService.insertUserWishGift(ordersGoodsGift));
    }

    /**
     * 修改订单商品赠品
     */
    @PreAuthorize("@ss.hasPermi('system:gift:edit')")
    @Log(title = "订单商品赠品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserWishGift ordersGoodsGift)
    {
        return toAjax(userWishGiftService.updateUserWishGift(ordersGoodsGift));
    }

    /**
     * 删除订单商品赠品
     */
    @PreAuthorize("@ss.hasPermi('system:gift:remove')")
    @Log(title = "订单商品赠品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ordersGoodsGiftIds}")
    public AjaxResult remove(@PathVariable Long[] ordersGoodsGiftIds)
    {
        return toAjax(userWishGiftService.deleteUserWishGiftByIds(ordersGoodsGiftIds));
    }
}
